var app = angular.module('conversionTool', []);

app.controller('taskFlowCtrl', [ '$scope', '$http', function($scope, $http) {

	$scope.taskFlow = new Object();

	$scope.checkFlowName = function() {

		if ($scope.taskFlow.taskFlowName == undefined || $scope.taskFlow.taskFlowName == "") {
			$scope.msg = "task flow name can not be empty";
			return false;
		}

	};

	$scope.getTasksByTaskFlowId = function() {
		
		if ($scope.taskFlow.id != undefined && $scope.taskFlow.id != "") {
			$http.post('/rest/task/getTasksByTaskFlowId', $scope.taskFlow.id).success(function(data) {

				$scope.tasks = data;

			}).error(function(data) {
				console.log(data);
			});
		}
	}

	$scope.deleteTask = function(id) {

		$http.post('/rest/task/deleteTaskById', id).success(function(data) {

			if (data == true) {
				$scope.getTasksByTaskFlowId();
				$scope.msg = "delete success!";
			} else {
				$scope.msg = "server error,please refresh!";
			}

		}).error(function(data) {
			console.log(data);
		});
	}
	
	
	
	
	$scope.viewLog=function(id)
	{
		location.href="/task/viewLogDetail?type=taskLog&id="+id;
	}
	
	$scope.viewData=function(id)
	{
		location.href="/task/viewTaskData?id="+id;
	}
	
	$scope.back=function(){
		
		window.history.back();
	}
	

	$scope.run = function() {
		
		
		$scope.msg="server is calling webservice!";

		$http.post('/rest/task/startTaskFlow', $scope.taskFlow.id).success(function(data) {

			$scope.msg="running over!";

		}).error(function(data) {
			console.log(data);
		});
	}

} ]);